//
//  HDCrashCollector.m
//  app
//
//  Created by 刘华舟 on 15/4/24.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDCrashCollector.h"


@implementation HDCrashCollector


- (BOOL)deleteLogFileAndStartToLog {
    
    [self finishLog];
    BOOL success = [[NSFileManager defaultManager] removeItemAtPath:[self loggingPath] error:nil];
    [self startLog];
    return success;
    
}

- (void)finishLog {
    
    fflush(stderr);
    dup2(dup(STDERR_FILENO), STDERR_FILENO);
    close(dup(STDERR_FILENO));
    
}

- (NSString*)loggingPath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"];
    NSLog(@"%@", logPath);
    return logPath;
    
}

- (void)startLog {
    freopen([[self loggingPath] cStringUsingEncoding:NSUTF8StringEncoding],"a+",stderr);
}










@end
